//http://www.kieser.net/linux/java_server.html
//http://www.dreamincode.net/forums/topic/74286-passing-data-between-clients-in-a-multithreaded-server-client-program/
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import org.xml.sax.SAXException;



public class ClientThread implements Runnable  {
	private Socket client;
	private int clientId;
	private XMLparser parser = new XMLparser();
	
	public ClientThread(Socket client, int clientId) {
		this.client = client;
		this.clientId = clientId;
	}

	@Override
	public void run() {
		try{
			// Send to the socket
			PrintWriter out = new PrintWriter(client.getOutputStream(), true);
			
			// Receive from the socket
			BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
	        String userinput;
	        
	        while ((userinput = in.readLine()) != null) {
	        	try {
					parser.parseFile(in);
				} catch (SAXException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	            System.out.println("Recieving data...");
			}
	        client.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
}
